// pages/shopInformation/shopInformation.js
const app = getApp();
import httpsUtils from '../../utils/https.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopList: [],
    current: 1,
    hasNextPage: true,
    isEmpty: false,
  },
  /**
  * 获取商品
  */
  getMyFocusShop: function (e) {
    wx.showLoading({
      title: '加载中...',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 8000)
    var that = this;
    httpsUtils.getData({
      _url: app.globalData._url + '/focusShop/selectPage?current=' + that.data.current,
      data: '',
    }, function (json) {
      if (json.success == false && json.code == 'OVERTIME') {
        wx.showModal({
          title: '登陆提醒',
          content: '需要您登陆才能查看',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '../wxLogin/wxLogin?type=7&isTab=false',
              })
            } else{
              wx.switchTab({
                url: '../myinfo/myinfo',
              })
            }
          }
        })
      } else if (json.data && json.success) {
        var shopList = that.data.shopList.concat(json.data.list);
        var isEmpty = false;
        if (shopList.length == 0) {
          isEmpty = true;
        }
        that.setData({
          shopList: shopList,
          current: json.data.pageNum,
          hasNextPage: json.data.hasNextPage,
          isEmpty: isEmpty
        })
      }
      wx.hideLoading();
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
    
  },
  // 事件函数

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;

    that.setData({
      shopList: [],
      current: 1,
      hasNextPage: true,
    })
    //获取关注店铺
    that.getMyFocusShop();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.hasNextPage) {
      that.setData({
        current: that.data.current + 1,
      })
      that.getMyFocusShop();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
    * 生命周期函数--监听页面加载
    */
  onPageScroll: function (event) {
  },

})